package com.zhentao.controller;

import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.wemedia.WmNewsDownOrUpDto;
import com.zhentao.model.common.wemedia.WmNewsDto;
import com.zhentao.model.common.wemedia.WmNewsPageReqDto;
import com.zhentao.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findAll(dto);
    }

    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) throws Exception {
        return wmNewsService.submitNews(dto);
    }

    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDownOrUpDto dto){
        return wmNewsService.downOrUp(dto);
    }

    //http://localhost:8802/wemedia/MEDIA/wemedia/api/v1/news/del_news/6250
    @GetMapping("/del_news/{id}")
    public ResponseResult del_news(@PathVariable("id") Integer id){
         return wmNewsService.removeById(id)?ResponseResult.okResult("删除成功"):ResponseResult.errorResult(500,"删除失败");
    }
}
